<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<x:parse xml="${param.xmlstr}" var="xmlData" />
<c:set var="title">经费预算表</c:set>
<c:if test="${not empty param.title }"><c:set var="title">${param.title }</c:set></c:if>

<!-- <div class="t_bar2">
	试制设备费预算明细表
</div> -->

<input type="hidden" name="proposal/orgnum" value="" id="orgNum">
<table  id="tblCooperation" cellpadding="0" class="table01 t_css" width="100%" border="0" cellpadding="0" style="*border-bottom: #a1c0dc 1px solid;">
			<col width="5%" />
			<col width="5%" />
			<col width="20%" />
			<col width="10%" />
			<col width="30%" />
			<col width="15%" />
			<col width="15%" />
			<thead >
					<tr style="border:1px solid #B7D1E6">
						<th class="TblHead" align="center" >选择</th>
						<th class="TblHead" align="center" >序号</th>
						<th class="TblHead" align="center" >完成单位名称</th>
						<th class="TblHead" align="center" >邮政编码</th>
						<th class="TblHead" align="center" >详细通信地址</th>
						<th class="TblHead" align="center" >隶属省部</th>
						<th class="TblHead" align="center" >单位属性</th> 
					</tr>
			</thead>
			<tbody id="tab">
					<tr style="display:none"  align="center">
						<td align="center">&nbsp;
							<input type="radio" class="radiobutton" name="selCooperation"  onclick="setSubmitOrg()">
						</td>
						<td align="center">
							<span name="organizations|organization[0]|seq_no" >[index]</span> 
						</td>
						<td align="center">&nbsp;
						<input type="text" name="organizations|organization[0]|org_name" label="完成单位名称"  maxlength="50" style="width:80%" class="required input_text"/>
						</td>
						<td align="center">
						<input type="text" name="organizations|organization[0]|zip_code" label="邮政编码"  maxlength="6" style="width:80%" class="hn_iuput_kuang required" />
						</td>
						<td align="center">&nbsp;
						<input type="text" name="organizations|organization[0]|address" label="详细通信地址"  maxlength="50" style="width:80%" class="required input_text"/>
						</td>
						<td align="center">&nbsp;
						<input type="text" name="organizations|organization[0]|indepart" label="隶属省部"  maxlength="50" style="width:80%" class="required input_text"/>
						</td>
						<td align="center">&nbsp;						
							<cpt:select id="region[index]"  name="orgtype" key="orgtype" onChange="initControlValue(this.id)"></cpt:select>
							<input type="hidden" name="organizations|organization[0]|orgtype_value" value="" label="单位属性"  class="required"/>
							<input type="hidden" name="organizations|organization[0]|orgtype_name" value="" label="单位属性"  />
						</td>
					</tr>
					<c:set value="0" var="index" scope="page"/>
					<x:forEach select="$xmlData/data/organizations/organization" var="organization">
					
					<c:choose>
						<c:when test="${index<10}" ><c:set value="0" var="flag" scope="page"/></c:when>
						<c:otherwise><c:set value="" var="flag" scope="page"/></c:otherwise>
					</c:choose>
					
					
					<c:choose>
						<c:when test="${index eq 0}">
							<tr   align="center">
								<td>&nbsp;
									<input type="radio" class="radiobutton" name="selCooperation"  onclick="setSubmitOrg()">
								</td>
								<td align="center">
									<span   name="organizations/organization[${flag}${index}]/seq_no" >${index+1 }</span> 
								</td>
								<td align="left">&nbsp;
								   <span name="organizations/organization[${flag}${index}]/org_name" ><x:out select="$organization/org_name" /></span>
								</td>
								<td align="center">
								   <span name="organizations/organization[${flag}${index}]/zip_code"> <x:out select="$organization/zip_code" /></span>
								</td>
								<td align="left">&nbsp;
								   <span name="organizations/organization[${flag}${index}]/address"> <x:out select="$organization/address" /></span>
								</td>
								<td align="center">&nbsp;
								   <span id="indepart" name="organizations/organization[${flag}${index}]/indepart"><x:out select="$xmlData/data/proposal/parent_department" /></span>
								</td>
								<td align="center">&nbsp;
									<input type="hidden" id="org_type_value" name="organizations/organization[${flag}${index}]/orgtype_value" value="<x:out select="$organization/orgtype_value" />" label="单位属性" />
									<span id="org_type_name" name="organizations/organization[${flag}${index}]/orgtype_name"><x:out select="$xmlData/data/proposal/orgtype_name" /></span>					
								</td>
							</tr>
						</c:when>
						<c:when test="${index ne 0}">
							<tr   align="center">
								<td>&nbsp;
									<input type="radio" class="radiobutton" name="selCooperation"  onclick="setSubmitOrg()">
								</td>
								<td align="center">
									<span   name="organizations/organization[${flag}${index}]/seq_no" >${index+1 }</span> 
								</td>
								<td align="center">&nbsp;
								   <input type="text" name="organizations/organization[${flag}${index}]/org_name"   label="完成单位名称"   style="width:80%" maxlength="50"  class="required input_text" value="<x:out select="$organization/org_name" />"/>
								</td>
								<td align="center">
								   <input type="text" name="organizations/organization[${flag}${index}]/zip_code"   label="邮政编码"   style="width:80%" maxlength="6"  class="hn_iuput_kuang required"  value="<x:out select="$organization/zip_code" />"/>
								</td>
								<td align="center">&nbsp;
								   <input type="text" name="organizations/organization[${flag}${index}]/address"   label="详细通信地址"   style="width:80%" maxlength="50"  class="required input_text" value="<x:out select="$organization/address" />"/>
								</td>
								<td align="center">&nbsp;
								   <input type="text" name="organizations/organization[${flag}${index}]/indepart"   label="隶属省部"   style="width:80%" maxlength="50"  class="required input_text" value="<x:out select="$organization/indepart" />"/>
								</td>
								<td align="center">&nbsp;						
								   <c:set var="orgtype_value"><x:out select="$organization/orgtype_value" /></c:set>
									<cpt:select id="region${index}" name="orgtype" value="${orgtype_value }" key="orgtype" onChange="initControlValue(this.id)" ></cpt:select>
									<input type="hidden" name="organizations/organization[${flag}${index}]/orgtype_value" value="<x:out select="$organization/orgtype_value" />" label="单位属性"  class="required"/>
									<input type="hidden" name="organizations/organization[${flag}${index}]/orgtype_name" label="单位属性" value="<x:out select="$organization/orgtype_name" />" />
								</td>
							</tr>
						</c:when>
					</c:choose>
					<c:set value="${index+1}" var="index" scope="page"/>
					</x:forEach>
				</tbody>
				
					</table>
					<table width="98%" align="center">
					<tr><td>
					<input class="button" id="cmdAddbefore" name="cmdAddbefore2" type=button value="添加" onclick="if(checkTabLimit('tblCooperation',20,'科技成果完成单位情况最多只能填写20条')){addNewRow('tblCooperation');showDateTag('tblCooperation');}try{top.resizeFrame();}catch(e){};">
					<input class="button" id="cmdMovePrev" name="cmdMovePrev2" type=button value="上移" onclick="movePrev2('tblCooperation','selCooperation')">
					<input class="button" id="cmdMoveNext" name="cmdMoveNext2" type=button value="下移" onclick="moveNext2('tblCooperation','selCooperation')">
					<input class="button" id="cmddel" name="cmddel2" type=button  value="删除" onclick="deleteSelectedRow2('tblCooperation','科技成果完成单位情况')">
					</td></tr>
	</table>

	<script type="text/javascript">
	
	/**
	 * 上移行
	 * @param tblId
	 * @returns {Boolean}
	 */
	function movePrev2(tblId,selName) {

		if (!selName)
			selName = "";
		if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
			scmWarn(irisNotes.prevWarn);
			return false;
		}
		if ($("#" + tblId + " tr").length <= 2)
			return false;
		var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
				.parents("tr").first();// 取得被选中的行
		var trPrev = trChecked.prev();// 取得上一行
		var index = trChecked.get(0).rowIndex;// 获得行号
		if (index <= 2) {// 如果是第一行
			scmWarn(irisNotes.tabelMoveWarn1);
			return false;
		}
		//trChecked.remove();
		trPrev.before(trChecked);
		trChecked.find(":radio[name*='" + selName + "']").attr("checked", 'true');
		refreshRowINdex2(tblId);
		setSubmitOrg() ;
	}

	/**
	 * 下移行
	 * @param tblId
	 * @returns {Boolean}
	 */
	function moveNext2(tblId,selName) {
		if (!selName)
			selName = "";
		if ($("#" + tblId + " :radio[name*='" + selName + "']:checked").length == 0) {
			scmWarn(irisNotes.nextWarn);
			return false;
		}
		if ($("#" + tblId + " tr").length <= 2) {
			return false;
		}
		var trChecked = $("#" + tblId + " :radio[name*='" + selName + "']:checked")
				.parents("tr").first();// 取得被选中的行
		var trNext = trChecked.next();
		var index = trChecked.get(0).rowIndex;// 获得行号
		if (index == $("#" + tblId + " tr").length - 1) {// 如果是第一行
			scmWarn(irisNotes.tabelMoveWarn2);
			return false;
		}
		//trChecked.remove();
		trNext.after(trChecked);
		trChecked.find(":radio[name*='" + selName + "']").attr("checked", "true");
		refreshRowINdex2(tblId);
		setSubmitOrg() ;
	}

	/**
	 * 重新计算行号
	 * @param tblId
	 */
	function refreshRowINdex2(tblId){
		 //重新计算行号

		
		  $("#"+tblId+" tr").each(function(){
			  
			   var seq=$(this).get(0).rowIndex;//获得行数
			   if(seq>1){//如果有行  显示时display行不计入类，故只减1
				   
				   seq=seq-1;
				   var seq_no=$(this).find("[name$='seq_no']");
				   if(seq_no.is("span"))
					   seq_no.html(seq);
				   else
					   seq_no.val(seq);
				   
				   seq=""+(seq-1);
				   if(seq.length==1)
					   seq="0"+seq;
				  //替换相应的name参数的seq
				  $(this).find("input,span,textarea,select").each(function(){
					   var name=$(this).attr("name");
					   if(name!=null&&name!=""){
						   name=name.replace(/\[\d*\]/g,"["+seq+"]");
						   $(this).attr("name",name);
					   }
					   var id=$(this).attr("id");
					   if(id!=null&&id!=""){
						   id=id.replace(/\[\d*\]/g,"["+seq+"]");
						   $(this).attr("id",id);
						   id=id.replace(/\d+/g,""+seq+"");
						   $(this).attr("id",id);
					   }
					   var className=$(this).attr("class");
					   if(className!=null&&className!=""){
						   className=className.replace(/\[\d*\]/g,"["+seq+"]");
						   $(this).attr("class",className);
					   }
				   });
			   }
			 }
		  );

	}
	
	
	/**
	 * 删除一行
	 * @param radioId 
	 */
	function deleteSelectedRow2(tableId,message,nummin,warnMsg,selName){
		if(!selName)selName="";
		var tr=$("#"+tableId+" :radio[name*='"+selName+"']:checked").parents("tr");
		if(nummin==null)
			nummin=0;
		var length=tr.length;
		if(tr.length==0)
			tr=$("#"+tableId+" tr").filter(":last");
		else if(tr.length>1)
			tr=tr.first();

		if(tr.get(0).rowIndex-1==nummin){
			scmWarn(irisNotes.delWarn1);
			return false;
		}
		if(length==0){
			
				scmWarn(irisNotes.delWarn2);
			
			return false;
		}
		  if(!confirm(messageTip.deleteTip+message+"？"))
			  return false;
		  tr.remove();
		  refreshRowINdex2(tableId);
		  return true;
		  setSubmitOrg() ;
	}
	
	
	function setSubmitOrg() {
		if($("#tblCooperation :radio:checked").length==0){
			scmWarn('请选择一行!');
			return false;
		}
		var tr = $("#tblCooperation :radio:checked").parents("tr");
		if (tr.get(0).rowIndex - 1 == 1) { 
			$("#cmdMovePrev").attr("disabled", "true").css("color", "#808080");
			$("#cmdMoveNext").attr("disabled", "true").css("color", "#808080");
			// $("#zh_psnEdit").attr("disabled","true").css("color","#808080");
			$("#cmddel").attr("disabled", "true").css("color", "#808080");

		} else if (tr.get(0).rowIndex - 1 == 2) {// 如果是申报书的下一行
			$("#cmdMovePrev").attr("disabled", "true").css("color", "#808080");
			$("#cmdMoveNext").removeAttr("disabled").css("color", "#FFFFFF");
			$("#cmddel").removeAttr("disabled").css("color", "#FFFFFF");
		} else {
			$("#cmdMovePrev").removeAttr("disabled").css("color", "#FFFFFF");
			$("#cmdMoveNext").removeAttr("disabled").css("color", "#FFFFFF");
			// $("#zh_psnEdit").removeAttr("disabled").css("color","#003366");
			$("#cmddel").removeAttr("disabled").css("color", "#FFFFFF");
		}
	}
	
	</script>
	
